﻿using SmallTool.BaseFile;
using SmallTool.frm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SmallTool
{
    public partial class frm_main : Form
    {
        public frm_main()
        {
            InitializeComponent();
        }

        private void tsm_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frm_main_Load(object sender, EventArgs e)
        {
            BaseCS.instance.Init();


        }

        /// <summary>
        /// 打开设置窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsm_setting_Click(object sender, EventArgs e)
        {
            OpenChildWindow<frm_setting>(this);
        }

        /// <summary>
        /// 打开查询窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsm_Select_Click(object sender, EventArgs e)
        {
            OpenChildWindow<frm_Select>(this);
        }

        private void ts_fileSavePath_Click(object sender, EventArgs e)
        {
            OpenChildWindow<frm_createFileSavePath>(this);
        }

        private void tsm_about_Click(object sender, EventArgs e)
        {
            OpenChildWindow<frm_about>(this);
        }

        private void ts_modify_Click(object sender, EventArgs e)
        {
            OpenChildWindow<frm_modify>(this);
        }

        private void ms_main_ItemAdded(object sender, ToolStripItemEventArgs e)
        {
            if (e.Item.Text.Length == 0 || e.Item.Text == "还原(&R)" || e.Item.Text == "最小化(&N)")
            {
                e.Item.Visible = false;
            }
        }

        private void OpenChildWindow<T>(Form mdiParent) where T : Form, new()
        {
            foreach (var item in mdiParent.MdiChildren)
            {
                if (item.GetType().Equals(typeof(T)))
                {
                    item.Activate();
                    return;
                }
            }

            T newForm = new T();
            newForm.MdiParent = mdiParent;
            newForm.WindowState = FormWindowState.Maximized;
            newForm.Show();
        }

        private void tsm_CalcActivityTime_Click(object sender, EventArgs e)
        {
            OpenChildWindow<frm_Calc>(this);
        }
    }
}
